from rest_framework import serializers

from user.models import User


class RegisterSerializer(serializers.ModelSerializer):
    username = serializers.CharField(label='用户名')
    token = serializers.CharField(label='JWT Token', read_only=True)

    class Meta:
        model = User
        fields = ['id', 'username', 'mobile', 'token', 'avatar', 'password']
        extra_kwargs = {
            "password": {
                'write_only': True
            }
        }
    def create(self, validated_data):
        user = User.objects.create_user(**validated_data)
        return user




from rest_framework import serializers
# from recruit.serializer import *
from user.models import User


class UserDetailSerializer(serializers.ModelSerializer):
    labels = serializers.StringRelatedField(many=True)
    questions = serializers.StringRelatedField(many=True)
    # answer_question = serializers.StringRelatedField(many=True)
    collected_articles = serializers.StringRelatedField(many=True)
    # enterpises =EnterpriseSerializer(many=True)
    username = serializers.CharField(read_only=True)

    class Meta:
        model = User
        fields = '__all__'